<template>
  <layout>
    <!-- 导航栏组件，包含标题、返回按钮等功能 -->
    <uv-navbar :fixed="false" :title="title" left-arrow @leftClick="$onClickLeft"/>
    <!-- 主体内容区域，当数据加载完成后显示 -->
    <view class="container" v-if="!loading">
      <!-- 店铺广告图片 -->
      <view>
        <image :src="shopAd" mode="aspectFill" class="w-100 " style="height: 250rpx;"></image>
      </view>
      <!-- 店铺公告栏，如果有公告则显示 -->
      <view style="height: 60rpx;background-color: #FFFFFF;" v-if="store.notice">
        <uv-notice-bar :text="store.notice"></uv-notice-bar>
      </view>
      <!-- 主要内容区域 -->
      <view class="main">
        <!-- 导航栏，包含店铺信息 -->
        <view class="nav">
          <view class="header">
            <!-- 店铺图标 -->
            <view class="mr-1">
              <image :src="store.image" style="width:80rpx ; height: 80rpx; "></image>
            </view>
            <!-- 店铺名称和位置 -->
            <view class="left">
              <view class="store-name">
                <text>{{ store.name }}</text>
              </view>
              <view class="store-location">
                <text>远方有个食堂</text>
              </view>
            </view>
          </view>
        </view>
        <!-- 内容区域，根据不同平台调整高度 -->
        <view class="content" :style="{height: 'calc(100vh - 500rpx + '+(store.notice ? '0rpx':'60rpx')+')'}">
          <!-- 菜单滚动视图，点击菜单项时滚动到对应商品列表 -->
          <scroll-view class="menus" :scroll-into-view="menuScrollIntoView" scroll-with-animation scroll-y>
            <view class="wrapper">
              <view class="menu" :id="`menu-${item.id}`" :class="{'current': item.id === currentCateId}" v-for="(item, index) in goods" :key="index" @tap="handleMenuTap(item.id)">
                <text>{{ item.name }}</text>
                <!-- 显示当前分类下的商品数量 -->
                <view class="dot" v-show="menuCartNum(item.id)">{{ menuCartNum(item.id) }}</view>
              </view>
            </view>
          </scroll-view>
          <!-- 商品列表滚动视图 -->
          <scroll-view class="goods" scroll-with-animation scroll-y :scroll-top="cateScrollTop"
                       @scroll="handleGoodsScroll">
            <view class="wrapper">
              <view class="list">
                <!-- 每个商品类别 -->
                <view class="category" v-for="(item, index) in goods" :key="index" :id="`cate-${item.id}`">
                  <view class="title">
                    <text>{{ item.name }}</text>
                    <image mode="aspectFill" :src="item.icon" class="icon"></image>
                  </view>
                  <view class="items">
                    <!-- 单个商品 -->
                    <view class="good" v-for="(good, key) in item.goodsList" :key="key">
                      <image mode="aspectFill" :src="good.image" class="image" @tap="showGoodDetailModal(item, good)"></image>
                      <view class="right">
                        <text class="name">{{ good.name }}</text>
                        <text class="tips">{{ good.info }}</text>
                        <view class="price_and_action">
                          <text class="price"></text>
                          <view class="btn-group">
                            <button type="primary" class="btn property_btn" hover-class="none" size="mini" @tap="showGoodDetailModal(item, good)">查看
                            </button>
                            <!-- 显示已添加到购物车的商品数量 -->
                            <view class="dot" v-show="goodCartNum(good.id)">{{ goodCartNum(good.id) }}</view>
                          </view>
                        </view>
                      </view>
                    </view>
                  </view>
                </view>
              </view>
            </view>
          </scroll-view>
        </view>
        <!-- 购物车栏，当购物车中有商品且购物车栏显示时显示 -->
        <view class="cart-box" v-if="cart.length > 0 && isCartShow">
          <view class="mark">
            <image src="/static/images/menu/cart.png" class="cart-img" @tap="openCartPopup"></image>
            <view class="tag">{{ getCartGoodsNumber }}</view>
          </view>
          <button type="primary" class="pay-btn" @tap="toPay">
            去结算
          </button>
        </view>
        <!-- 商品详情模态框，显示商品详细信息 -->
        <modal :show="goodDetailModalVisible" class="good-detail-modal" color="#5A5B5C" width="90%" custom
               padding="0rpx" radius="12rpx">
          <view class="cover">
            <view class="btn-group">
              <image src="/static/images/menu/close.png" @tap="closeGoodDetailModal"></image>
            </view>
          </view>
          <scroll-view class="detail" scroll-y>
            <view v-if="good.image" class="image">
              <image :src="good.image"></image>
            </view>
            <view class="wrapper">
              <view class="basic">
                <view class="name">{{ good.name }}</view>
                <view class="tips flex justify-between">{{ good.info }}</view>
              </view>
            </view>
          </scroll-view>
          <view class="add-to-cart-btn" @tap="handleAddToCartInModal">
            <view>加入购物车</view>
          </view>
        </modal>

        <!-- 购物车详情弹出层 -->
        <uv-popup ref="popup" mode="bottom" class="cart-popup">
          <template #default>
            <view class="cart-popup">
              <view class="top">
                <text @tap="handleCartClear">清空</text>
              </view>
              <scroll-view class="cart-list" scroll-y>
                <view class="wrapper">
                  <!-- 购物车中的每个商品 -->
                  <view class="item" v-for="(item, index) in cart" :key="index">
                    <view class="left">
                      <view class="name">{{ item.name }}</view>
                    </view>
                    <view class="center"></view>
                    <view class="right">
                      <!-- 减少商品数量 -->
                      <button type="default" plain size="mini" class="btn" hover-class="none"
                              @tap="handleCartItemReduce(index)">
                        <view class="iconfont iconsami-select"></view>
                      </button>
                      <view class="number">{{ item.number }}</view>
                      <!-- 增加商品数量 -->
                      <button type="primary" class="btn" size="min" hover-class="none" @tap="handleCartItemAdd(index)">
                        <view class="iconfont iconadd-select"></view>
                      </button>
                    </view>
                  </view>
                </view>
              </scroll-view>
            </view>
          </template>
        </uv-popup>
        <uv-toast ref="uToast"></uv-toast>
      </view>

    </view>
  </layout>
</template>

<script setup>
import {ref, computed, nextTick} from 'vue'
import {useMainStore} from '@/store/store'
import {storeToRefs} from 'pinia'
import {onLoad, onShow, onPullDownRefresh, onHide} from '@dcloudio/uni-app'
import {shopNearby, menuGoods} from '@/api/goods'
import {menuAds} from '@/api/market'

const main = useMainStore()
const {store, location, isLogin} = storeToRefs(main)
const title = ref('点餐')
const goods = ref([]) // 商品列表
const ads = ref([]) // 广告列表
const loading = ref(true) // 加载状态
const currentCateId = ref(0) // 当前选中的分类ID
const cateScrollTop = ref(0) // 分类滚动位置
const menuScrollIntoView = ref('') // 菜单滚动视图
const cart = ref([]) // 购物车
const goodDetailModalVisible = ref(false) // 商品详情模态框可见性
const good = ref({}) // 当前商品
const category = ref({}) // 当前分类
const cartPopupVisible = ref(false) // 购物车弹出层可见性
const sizeCalcState = ref(false) // 尺寸计算状态
const shopAd = ref('') // 店铺广告
const isCartShow = ref(true) // 购物车显示状态
const popup = ref() // 弹出层组件引用

// 计算单个商品添加到购物车的数量
const goodCartNum = computed(() => (id) =>
    cart.value.reduce((acc, cur) => acc + (cur.id === id ? cur.number : 0), 0)
)

// 计算分类下的商品数量
const menuCartNum = computed(() => (id) =>
    cart.value.reduce((acc, cur) => acc + (cur.cate_id === id ? cur.number : 0), 0)
)

// 计算购物车总数
const getCartGoodsNumber = computed(() =>
    cart.value.reduce((acc, cur) => acc + cur.number, 0)
)

// 监听自定义事件
uni.$on('refreshMenu', () => {
  console.log('refreshMenu1:', store.value.id)
  init()
})

// 下拉刷新事件
onPullDownRefresh(() => {
  init()
})

// 页面加载事件
onLoad(() => {
  init()
})

// 隐藏页面事件
onHide(() => {
  sizeCalcState.value = false
})

// 显示页面事件
onShow(() => {
  console.log("into show...")
  shopAd.value = uni.getStorageSync('shopAd')
  refreshCart()
})

// 初始化页面
const init = async () => {
  loading.value = true
  let result = location.value
  getShopList(result)
  loading.value = false
}

// 获取店铺列表
const getShopList = async (res) => {
  goods.value = []
  if (!res) {
    return
  }

  main.SET_LOCATION(res)
  let shop_id = store.value.id || 0
  let resp = await shopNearby({
    lat: res.latitude,
    lng: res.longitude,
    shop_id: shop_id,
    kw: ''
  })

  let shop = resp?.shop?.[0] || {}
  if (!shop) {
    return
  }

  getAds(shop.id)
  main.SET_STORE(shop)
  let mygoods = await menuGoods({shopId: shop.id})
  if (mygoods) {
    mygoods.list.forEach(item => {
      let goodsList = []
      let product = mygoods.product_map[item.id]
      if (product) {
        product.list.forEach(productItem => {
          goodsList.push({
            ...productItem,
          })
        })
      }
      goods.value.push({
        ...item,
        goodsList: goodsList,
      })
    })
    refreshCart()
  }
  uni.stopPullDownRefresh()
}

// 刷新购物车
const refreshCart = () => {
  if (goods.value && goods.value.length > 0) {
    let newGoods = goods.value
    cart.value = []
    let newCart = uni.getStorageSync('cart') || []
    console.log("newCart",newCart)
    let tmpCart = []
    if (newCart) {
      for (let i in newCart) {
        for (let ii in newGoods) {
          for (let iii in newGoods[ii].goodsList) {
            if (newCart[i].id === newGoods[ii].goodsList[iii].id) {
              tmpCart.push(newCart[i])
            }
          }
        }
      }
      cart.value = tmpCart
      cartPopupVisible.value = false
    }
  }
}

// 获取广告
const getAds = async (shop_id) => {
  shop_id = shop_id || 0
  let data = await menuAds({
    list_option: {
      options: [{key: 1, value: shop_id.toString()}],
      skip_total: true,
    }
  })
  if (data) {
    ads.value = data.list
  }
}

// 点击菜单项事件
const handleMenuTap = (id) => {
  if (!sizeCalcState.value) {
    calcSize()
  }
  currentCateId.value = id
  nextTick(() => cateScrollTop.value = goods.value.find(item => item.id === id)?.top || 0)
}

// 商品列表滚动事件
const handleGoodsScroll = ({detail}) => {
  if (!sizeCalcState.value) {
    calcSize()
  }
  const {scrollTop} = detail
  let tabs = goods.value.filter(item => item.top <= scrollTop).reverse()
  if (tabs.length > 0) {
    currentCateId.value = tabs[0].id
  }
}

// 计算尺寸
const calcSize = () => {
  let h = 10
  let view = uni.createSelectorQuery().select('#ads')
  if (view) {
    view.fields({size: true}, data => {
      if (data) {
        h += Math.floor(data.height)
      }
    }).exec()
  }
  goods.value.forEach(item => {
    let view = uni.createSelectorQuery().select(`#cate-${item.id}`)
    view.fields({size: true}, data => {
      item.top = h
      h += data.height
      item.bottom = h
    }).exec()
  })
  sizeCalcState.value = true
}

// 添加到购物车
const handleAddToCart = (cate, newGood, num) => {
  const index = cart.value.findIndex(item => (item.id === newGood.id))
  console.log("index", index)
  if (index > -1) {
    cart.value[index].number += num
  } else {
    cart.value.push({
      id: newGood.id,
      cate_id: cate.id,
      name: newGood.name,
      number: num,
      image: newGood.image,
    })
  }
  uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
}

// 显示商品详情模态框
const showGoodDetailModal = (item, newGood) => {
  isCartShow.value = true
  good.value = JSON.parse(JSON.stringify({...newGood, number: 1}))
  category.value = JSON.parse(JSON.stringify(item))
  goodDetailModalVisible.value = true
}

// 关闭商品详情模态框
const closeGoodDetailModal = () => {
  goodDetailModalVisible.value = false
  category.value = {}
  good.value = {}
}

// 在模态框中添加到购物车
const handleAddToCartInModal = () => {
  handleAddToCart(category.value, good.value, good.value.number)
  closeGoodDetailModal()
}

// 打开/关闭购物车列表popup
const openCartPopup = () => {
  popup.value.open()
}

// 清空购物车
const handleCartClear = () => {
  uni.showModal({
    title: '提示',
    content: '确定清空购物车么',
    success: ({confirm}) => {
      if (confirm) {
        popup.value.close()
        cart.value = []
        uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
      }
    }
  })
}

// 增加购物车中商品数量
const handleCartItemAdd = (index) => {
  cart.value[index].number += 1
  uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
}

// 减少购物车中商品数量
const handleCartItemReduce = (index) => {
  if (cart.value[index].number === 1) {
    cart.value.splice(index, 1)
  } else {
    cart.value[index].number -= 1
  }
  if (!cart.value.length) {
    cartPopupVisible.value = false
  }
  uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
}

// 去支付
const toPay = () => {
  if (!isLogin.value) {
    uni.navigateTo({url: '/pages/components/pages/login/login'})
    return
  }
  uni.showLoading({title: '加载中'})
  uni.setStorageSync('cart', JSON.parse(JSON.stringify(cart.value)))
  uni.navigateTo({url: '/pages/components/pages/pay/pay'})
  uni.hideLoading()
}
</script>

<style lang="scss" scoped>
/* #ifdef H5 */
page {
  height: auto;
  min-height: 100%;
}

/* #endif */

.container {
  overflow: hidden;
  position: relative;
}

.loading {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;

  image {
    width: 260rpx;
    height: 260rpx;
    position: relative;
    margin-top: -200rpx;
    /* #ifdef h5 */
    margin-top: 0;
    /* #endif */
  }
}

.stores {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  margin-bottom: -40rpx;

  .store {
    width: 100%;
    background-color: $bg-color-grey;
    padding: 20rpx;
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
    border-radius: 6rpx;

    .iconfont {
      font-size: 50rpx;
      margin-right: 15rpx;

      &.iconradio-button-off {
        color: $text-color-assist;
      }

      &.iconradio-button-on {
        color: $color-primary;
      }
    }

    .infos {
      flex: 1;
      display: flex;
      flex-direction: column;
      color: $text-color-base;
      overflow: hidden;

      .name_and_distance {
        width: 100%;
        display: flex;
        justify-content: space-between;
        margin-bottom: 10rpx;
        overflow: hidden;

        .name {
          flex: 1;
          flex-shrink: 0;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-size: $font-size-lg;
        }

        .distance {
          flex-shrink: 0;
          font-size: $font-size-lg;
          font-weight: bold;
          margin-left: 20rpx;
        }
      }

      .street {
        color: $text-color-assist;
        font-size: $font-size-sm;
      }
    }
  }
}

.main {
  width: 100%;
  height: 100%;
  position: relative;
}

.nav {
  width: 100%;
  //height: 212rpx;
  height: 140rpx;
  display: flex;
  flex-direction: column;

  .header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20rpx;
    background-color: #ffffff;
    height: 140rpx;

    .left {
      flex: 1;
      display: flex;
      flex-direction: column;

      .store-name {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        font-size: $font-size-lg;
        margin-bottom: 10rpx;

        .small {
          font-size: $font-size-sm;
          color: $text-color-assist;
        }

        .iconfont {
          margin-left: 10rpx;
          line-height: 100%;
        }
      }

      .store-location {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        color: $text-color-assist;
        font-size: $font-size-sm;

        .iconfont {
          vertical-align: middle;
          display: table-cell;
          color: $color-primary;
          line-height: 100%;
        }
      }
    }

    .right {
      background-color: $bg-color-grey;
      border-radius: 38rpx;
      display: flex;
      align-items: center;
      font-size: $font-size-sm;
      padding: 0 38rpx;
      color: $text-color-assist;

      .dinein,
      .takeout {
        position: relative;
        display: flex;
        align-items: center;

        &.active {
          padding: 14rpx 38rpx;
          color: #ffffff;
          background-color: $color-primary;
          //background-color: #5A5B5C;
          border-radius: 38rpx;
        }
      }

      .takeout {
        margin-left: 20rpx;
        height: 100%;
        flex: 1;
        padding: 14rpx 0;
      }

      .dinein.active {
        margin-left: -38rpx;
      }

      .takeout.active {
        margin-right: -38rpx;
      }
    }
  }

  .coupon {
    flex: 1;
    width: 100%;
    background-color: $bg-color-primary;
    font-size: $font-size-base;
    color: $color-primary;
    padding: 0 20rpx;
    display: flex;
    align-items: center;
    overflow: hidden;

    .title {
      flex: 1;
      margin-left: 10rpx;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    .iconfont {
      line-height: 100%;
    }
  }
}

.content {
  width: 100%;
  height: calc(100vh - 212rpx);
  /* #ifdef H5 */
  height: calc(100vh - 212rpx - 188rpx);
  /* #endif */
  display: flex;

  .menus {
    width: 200rpx;
    height: 100%;
    overflow: hidden;
    background-color: $bg-color-grey;

    .wrapper {
      width: 100%;
      height: 100%;

      .menu {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        padding: 30rpx 20rpx;
        font-size: 26rpx;
        color: $text-color-assist;
        position: relative;

        &.current {
          background-color: #ffffff;
          color: $text-color-base;
        }

        .dot {
          position: absolute;
          width: 34rpx;
          height: 34rpx;
          line-height: 34rpx;
          font-size: 22rpx;
          background-color: $color-primary;
          //background-color: #5A5B5C;
          color: #ffffff;
          top: 16rpx;
          right: 10rpx;
          border-radius: 100%;
          text-align: center;
        }
      }

      .menu:last-child {
        margin-bottom: 200rpx;
      }
    }
  }

  .goods {
    flex: 1;
    height: 100%;
    overflow: hidden;
    background-color: #ffffff;

    .wrapper {
      width: 100%;
      height: 100%;
      padding: 20rpx;

      .ads {
        height: calc(300 / 550 * 510rpx);

        image {
          width: 100%;
          height: 100%;
          border-radius: 8rpx;
        }
      }

      .list {
        width: 100%;
        font-size: $font-size-base;

        .category {
          width: 100%;

          .title {
            padding: 30rpx 0;
            display: flex;
            align-items: center;
            color: $text-color-base;

            .icon {
              width: 38rpx;
              height: 38rpx;
              margin-left: 10rpx;
            }
          }
        }

        .category:last-child {
          margin-bottom: 200rpx;
        }

        .items {
          display: flex;
          flex-direction: column;
          padding-bottom: -30rpx;

          .good {
            display: flex;
            align-items: center;
            //margin-bottom: 30rpx;
            padding: 15rpx 0;

            .image {
              width: 160rpx;
              height: 160rpx;
              margin-right: 20rpx;
              border-radius: 8rpx;
            }

            .right {
              flex: 1;
              height: 160rpx;
              overflow: hidden;
              display: flex;
              flex-direction: column;
              align-items: flex-start;
              justify-content: space-between;
              padding-right: 14rpx;

              .name {
                font-size: $font-size-base;
                margin-bottom: 10rpx;
                width: 100%;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
              }

              .tips {
                width: 100%;
                height: 40rpx;
                line-height: 40rpx;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                font-size: $font-size-sm;
                color: $text-color-assist;
                margin-bottom: 10rpx;
              }

              .price_and_action {
                width: 100%;
                display: flex;
                justify-content: space-between;
                align-items: center;

                .price {
                  font-size: $font-size-base;
                  font-weight: 600;
                }

                .btn-group {
                  display: flex;
                  justify-content: space-between;
                  align-items: center;
                  position: relative;

                  .btn {
                    padding: 0 20rpx;
                    box-sizing: border-box;
                    font-size: $font-size-sm;
                    height: 44rpx;
                    line-height: 44rpx;

                    &.property_btn {
                      border-radius: 24rpx;
                    }

                    &.add_btn,
                    &.reduce_btn {
                      padding: 0;
                      width: 44rpx;
                      border-radius: 44rpx;
                    }
                  }

                  .dot {
                    position: absolute;
                    background-color: #ffffff;
                    border: 1px solid $color-primary;
                    color: $color-primary;
                    font-size: $font-size-sm;
                    width: 36rpx;
                    height: 36rpx;
                    line-height: 36rpx;
                    text-align: center;
                    border-radius: 100%;
                    right: -12rpx;
                    top: -10rpx;
                  }

                  .number {
                    width: 44rpx;
                    height: 44rpx;
                    line-height: 44rpx;
                    text-align: center;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

.modal-box {
  max-height: 90vh;
}

.good-detail-modal {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .cover {
    height: 20rpx;
    display: flex;
    justify-content: center;
    align-items: center;

    .btn-group {
      position: absolute;
      right: 10rpx;
      top: 0rpx;
      display: flex;
      align-items: center;
      justify-content: space-around;
      z-index: 210;

      image {
        width: 80rpx;
        height: 80rpx;
      }
    }
  }

  .detail {
    width: 100%;
    min-height: 1vh;
    max-height: calc(90vh - 320rpx - 80rpx - 120rpx);
    position: relative;

    .image {
      display: flex;
      justify-content: center;
      align-items: center;

      image {
        width: 260rpx;
        height: 260rpx;
      }
    }

    .wrapper {
      width: 100%;
      height: 100%;
      overflow: hidden;

      .basic {
        padding: 0 20rpx 30rpx;
        display: flex;
        flex-direction: column;

        .name {
          font-size: $font-size-base;
          color: $text-color-base;
          margin-bottom: 10rpx;
        }

        .tips {
          font-size: $font-size-sm;
          color: $text-color-grey;
        }
      }

      .properties {
        width: 100%;
        border-top: 2rpx solid $bg-color-grey;
        padding: 10rpx 30rpx 0;
        display: flex;
        flex-direction: column;

        .property {
          width: 100%;
          display: flex;
          flex-direction: column;
          margin-bottom: 30rpx;
          padding-bottom: -16rpx;

          .title {
            width: 100%;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            margin-bottom: 20rpx;

            .name {
              font-size: 26rpx;
              color: $text-color-base;
              margin-right: 20rpx;
            }

            .desc {
              flex: 1;
              font-size: $font-size-sm;
              color: $color-primary;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
          }

          .values {
            width: 100%;
            display: flex;
            flex-wrap: wrap;

            .value {
              border-radius: 8rpx;
              background-color: $bg-color-grey;
              padding: 16rpx 30rpx;
              font-size: 26rpx;
              color: $text-color-assist;
              margin-right: 16rpx;
              margin-bottom: 16rpx;

              &.default {
                background-color: $color-primary;
                color: $text-color-white;
              }
            }
          }
        }
      }
    }
  }

  .action {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: $bg-color-grey;
    height: 120rpx;
    padding: 0 26rpx;

    .left {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      margin-right: 20rpx;
      overflow: hidden;

      .price {
        font-size: $font-size-lg;
        color: $text-color-base;
      }

      .props {
        color: $text-color-assist;
        font-size: 24rpx;
        width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    .btn-group {
      display: flex;
      align-items: center;
      justify-content: space-around;

      .number {
        font-size: $font-size-base;
        width: 44rpx;
        height: 44rpx;
        line-height: 44rpx;
        text-align: center;
      }

      .btn {
        padding: 0;
        font-size: $font-size-base;
        width: 44rpx;
        height: 44rpx;
        line-height: 44rpx;
        border-radius: 100%;
      }
    }
  }

  .add-to-cart-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: $color-primary;
    color: $text-color-white;
    font-size: $font-size-base;
    height: 80rpx;
    border-radius: 0 0 12rpx 12rpx;
  }
}

.cart-box {
  position: fixed;
  bottom: 30rpx;
  left: 30rpx;
  right: 30rpx;
  height: 96rpx;
  border-radius: 48rpx;
  box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.2);
  background-color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 9999;

  .cart-img {
    width: 96rpx;
    height: 96rpx;
    position: relative;
    margin-top: -48rpx;
  }

  .pay-btn {
    height: 100%;
    padding: 0 30rpx;
    color: #ffffff;
    border-radius: 0 50rpx 50rpx 0;
    display: flex;
    align-items: center;
    font-size: $font-size-base;
  }

  .mark {
    padding-left: 46rpx;
    margin-right: 30rpx;
    position: relative;

    .tag {
      //background-color: $color-warning;
      background-color: #dd524d;;
      color: $text-color-white;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: $font-size-sm;
      position: absolute;
      right: -10rpx;
      top: -50rpx;
      border-radius: 100%;
      padding: 4rpx;
      width: 40rpx;
      height: 40rpx;
      opacity: 0.9;
    }
  }

  .price {
    flex: 1;
    color: $text-color-base;
  }
}

.cart-popup {
  .top {
    background-color: $bg-color-primary;
    //color: $color-primary;
    color: #5A5B5C;
    padding: 10rpx 30rpx;
    font-size: 24rpx;
    text-align: right;
  }

  .cart-list {
    background-color: #ffffff;
    width: 100%;
    overflow: hidden;
    min-height: 1vh;
    max-height: 60vh;

    .wrapper {
      height: 100%;
      display: flex;
      flex-direction: column;
      padding: 0 30rpx;
      margin-bottom: 156rpx;

      .item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx 0;
        position: relative;

        &::after {
          content: ' ';
          position: absolute;
          bottom: 0;
          left: 0;
          width: 100%;
          background-color: $border-color;
          height: 2rpx;
          transform: scaleY(0.6);
        }

        .left {
          flex: 1;
          display: flex;
          flex-direction: column;
          overflow: hidden;
          margin-right: 30rpx;

          .name {
            font-size: $font-size-sm;
            color: $text-color-base;
          }

          .props {
            color: $text-color-assist;
            font-size: 24rpx;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }

        .center {
          margin-right: 120rpx;
          font-size: $font-size-base;
        }

        .right {
          display: flex;
          align-items: center;
          justify-content: space-between;

          .btn {
            width: 46rpx;
            height: 46rpx;
            border-radius: 100%;
            padding: 0;
            text-align: center;
            line-height: 46rpx;
          }

          .number {
            font-size: $font-size-base;
            width: 46rpx;
            height: 46rpx;
            text-align: center;
            line-height: 46rpx;
          }
        }
      }
    }
  }
}

.backgroud-grey {
  background-color: #e1e4e4;
  padding: 15rpx !important;
}
</style>
